package com.kexin.jbsg.guansdk.interfaces;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.kexin.jbsg.AbstractUnityActivity;
import com.kexin.jbsg.guansdk.KomSDKInfo;
import com.kexin.jbsg.guansdk.LoginActivity;
import com.kexin.jbsg.guansdk.callback.LoginCallBack;

/**
 * @author oven:
 * @version 创建时间：2013-6-18 下午4:06:05
 * 
 */
public abstract class GuanSDK extends AbstractUnityActivity{
	public static GuanSDK instance = null;
	protected Boolean m_loginSucc = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
        KomSDKInfo.initSDK(channel);
        instance = this;
        checkNetwork();
	}
	
	
	@Override
	public void login(){
		KomSDKInfo.getInstance().openLoginActivity(this,new LoginCallBack() {
			@Override
			public void userLogin(String userAccount, int time, String sign) {
				onLoginSuccess(userAccount,time,sign);
			}
			
			@Override
			public void userCancel() {
				onLoginUserCancel();
			}
		});
	}
	
	public void clickBackGame(){
		LoginActivity.instance.finish();
	}
	
	/**
	 * 具体平台重写这方法回调
	 */
	protected void onLoginSuccess(String userAccount, int time, String sign){
		Toast.makeText(GuanSDK.this, "登录成功!", Toast.LENGTH_LONG).show();
		sendLoginSuccessMessage(userAccount+","+time+","+sign);
	}
	
	protected void onLoginUserCancel(){
		Toast.makeText(GuanSDK.this, "用户取消登录", Toast.LENGTH_LONG).show();
		GuanSDK.this.finish();
	}
	
	
	//打开其他界面返回数据
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode==KomSDKInfo.RESULT_CODE_LOGIN){
			Bundle bd = data.getExtras();
			if(bd!=null&&bd.containsKey("loginResult")){
				String userAccount = bd.getString("userAccount");
				String sign = bd.getString("sign");
				int time = bd.getInt("time");
				KomSDKInfo.instance.getLoginCallBack().userLogin(userAccount, time, sign);
			}else{
				KomSDKInfo.instance.getLoginCallBack().userCancel();
			}
		}
	}
	
}

